﻿
#include "lgCommon.h"
#include "lgDB_CPUFlash.h"
#include "flash.h"

//   0-----102400  程序区域
//  102400+nFlashAdd 操作地址
//   (102400+nFlashAdd)/512    nFlashAdd < 512      操作地址所在sector
//
#define MCU_FLASH_BASE_ADD  102400

char  cOKFlag[4] = {0x12,0x34,0x5A,0xA5};


void  lgMCU_FLASH_WriteFlag()
{
     // Erase 99th sector */// Flash_EraseSector(100*FLASH_SECTOR_SIZE);
      int  i ;
      int  k;
      int  nPos = 0;

      Flash_EraseSector(MCU_FLASH_BASE_ADD);

      Flash_Program(MCU_FLASH_BASE_ADD,&cOKFlag[0],4);
 }

/*
void lgMCU_FLASH_WriteByte(int   nFlashAdd,uint8_t  pData)
{
     int  sector = (MCU_FLASH_BASE_ADD + nFlashAdd)/(FLASH_SECTOR_SIZE);
     uint8_t    tmpSecData[FLASH_SECTOR_SIZE] = {0};
     lgMCU_FLASH_Read(sector*FLASH_SECTOR_SIZE - MCU_FLASH_BASE_ADD , tmpSecData,FLASH_SECTOR_SIZE);
     int    nOffSet = nFlashAdd%FLASH_SECTOR_SIZE;
     Flash_EraseSector(sector*FLASH_SECTOR_SIZE);
     tmpSecData[nOffSet] = pData;
     Flash_Program( sector*FLASH_SECTOR_SIZE,&tmpSecData[0],512 );
}
*/


int  lgMCU_FLASH_ReadFlag()
{
     uint32_t tmpVal =  *((uint32_t *)MCU_FLASH_BASE_ADD);
     if(tmpVal == 0xA55A3412)
         return 1;
     else
         return 0;
}




